package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.anno.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface DishMapper {

    /**
     * 查询总数了通过分类id
     * @param id
     * @return
     */
    @Select("select * from dish where category_id = #{id}")
    List<Dish> getByCateGory(Long id);

    /**
     * 新增菜品
     * @param dish
     */
    @AutoFill(OperationType.INSERT)
    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Insert("insert into dish value (null,#{name},#{categoryId},#{price},#{image}," +
            "#{description},#{status},#{createTime},#{updateTime},#{createUser}," +
            "#{updateUser})")
    void insert(Dish dish);

    /**
     * 分页查询
     * @param dto
     * @return
     */
    Page list(DishPageQueryDTO dto);

    /**
     * 批量查询菜品
     * @param ids
     * @return
     */
    List<Dish> getByIds(List<Long> ids);

    /**
     * 查询菜品关联的套餐个数
     * @param ids
     * @return
     */
    Integer getSetmealDish(List<Long> ids);

    /**
     * 批量删除菜品
     * @param ids
     */
    void deleteBatch(List<Long> ids);
    /**
     * 根据id查询菜品
     * @param id
     * @return
     */
    Dish getById(Long id);

    /**
     * 修改菜品
     * @param dish
     */
    @AutoFill(OperationType.INSERT)
    void update(Dish dish);

    /**
     * 查询菜品
     * @param categoryId
     * @return
     */
    List<DishVO> getList(Long categoryId);
}
